<template>
  <div class="dashboard">
    
    <el-row :gutter="20" class="content-row">
      <el-col :span="16">
        <el-card class="chart-card">
          <template #header>
            <div class="card-header">
              <span>用户增长趋势</span>
            </div>
          </template>
          <div class="chart-container">
            <el-empty description="图表占位符" />
          </div>
        </el-card>
      </el-col>
      
      <el-col :span="8">
        <el-card class="recent-card">
          <template #header>
            <div class="card-header">
              <span>最近活动</span>
            </div>
          </template>
          <div class="recent-list">
            <div 
              v-for="activity in recentActivities" 
              :key="activity.id"
              class="activity-item"
            >
              <div class="activity-icon">
                <el-icon :color="activity.color"><component :is="activity.icon" /></el-icon>
              </div>
              <div class="activity-content">
                <div class="activity-title">{{ activity.title }}</div>
                <div class="activity-time">{{ activity.time }}</div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { User, Monitor, HomeFilled, Connection, Plus, Edit, Delete } from '@element-plus/icons-vue'

// 统计数据
const stats = ref({
  users: 128,
  devices: 342,
  families: 24,
  online: 287
})

// 最近活动
const recentActivities = ref([
  {
    id: 1,
    title: '新增用户 admin',
    time: '5分钟前',
    icon: Plus,
    color: '#409EFF'
  },
  {
    id: 2,
    title: '更新用户信息',
    time: '1小时前',
    icon: Edit,
    color: '#67C23A'
  },
  {
    id: 3,
    title: '删除用户 test',
    time: '2小时前',
    icon: Delete,
    color: '#F56C6C'
  },
  {
    id: 4,
    title: '设备上线通知',
    time: '3小时前',
    icon: Connection,
    color: '#E6A23C'
  }
])

onMounted(() => {
  // 这里可以调用API获取真实数据
  console.log('Dashboard mounted')
})
</script>

<style scoped>
.dashboard {
  padding: 20px;
}

.stats-row {
  margin-bottom: 20px;
}

.stat-card {
  border-radius: 8px;
  overflow: hidden;
}

.stat-content {
  display: flex;
  align-items: center;
}

.stat-icon {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
  font-size: 24px;
}

.stat-icon.users {
  background-color: #ecf5ff;
  color: #409eff;
}

.stat-icon.devices {
  background-color: #f0f9eb;
  color: #67c23a;
}

.stat-icon.families {
  background-color: #fdf6ec;
  color: #e6a23c;
}

.stat-icon.online {
  background-color: #f4f4f5;
  color: #909399;
}

.stat-info {
  flex: 1;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 14px;
  color: #999;
}

.chart-card, .recent-card {
  border-radius: 8px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chart-container {
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.recent-list {
  height: 300px;
  overflow-y: auto;
}

.activity-item {
  display: flex;
  padding: 15px 0;
  border-bottom: 1px solid #eee;
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-icon {
  margin-right: 15px;
  font-size: 18px;
}

.activity-content {
  flex: 1;
}

.activity-title {
  font-size: 14px;
  margin-bottom: 5px;
}

.activity-time {
  font-size: 12px;
  color: #999;
}
</style>